package com.leenleda.ips.activity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.leenleda.ips.R;
import com.leenleda.ips.databinding.ItemImageBinding;
import com.leenleda.ips.entity.InsertBean;
import com.leenleda.ips.receiver.Constant;
import com.leenleda.ips.util.FileUtils;
import com.leenleda.ips.util.LogUtils;
import com.leenleda.ips.widget.banner.BannerAdapter;

import java.util.List;

public class InsertAdapter extends BannerAdapter<InsertBean.FileRecordsBean, InsertAdapter.ViewHolder> {

    private Context context;
    public InsertAdapter(Context context, List<InsertBean.FileRecordsBean> mDatas) {
        //设置数据，也可以调用banner提供的方法,或者自己在adapter中实现
        super(mDatas);
        this.context = context;
        filePath = FileUtils.getPath(Constant.CACHE_FOLDER);
    }

    //更新数据
    public void updateData(List<InsertBean.FileRecordsBean> data) {
        //这里的代码自己发挥，比如如下的写法等等
        mDatas.clear();
        mDatas.addAll(data);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public InsertAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemImageBinding binding = ItemImageBinding.bind(LayoutInflater.from(context).inflate(R.layout.item_image,parent,false));
        return new InsertAdapter.ViewHolder(binding);
    }

    @Override
    public InsertAdapter.ViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        ItemImageBinding binding = ItemImageBinding.bind(LayoutInflater.from(context).inflate(R.layout.item_image,parent,false));
        return new InsertAdapter.ViewHolder(binding);
    }

    private String filePath = "";
    @Override
    public void onBindView(InsertAdapter.ViewHolder holder, InsertBean.FileRecordsBean data, int position, int size) {
        final ItemImageBinding binding=(ItemImageBinding) holder.getBinding();



        LogUtils.e("DFSDFSDF", "==save=======getPath==" + data.getPath());
        Glide.with(context)
                .asBitmap()
                .load(data.getPath())
                .into(binding.scanImage);
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private ViewDataBinding binding;
        public ViewHolder(ViewDataBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
        public ViewDataBinding getBinding() {
            return binding;
        }
    }
}
